package cn.itcast.search.controller;

import cn.itcast.hmall.dto.common.PageDTO;
import cn.itcast.hmall.dto.common.ResultDTO;
import cn.itcast.hmall.dto.search.SearchReqDTO;
import cn.itcast.hmall.pojo.item.ItemDoc;
import cn.itcast.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 导入es数据
     * @return
     */
    @GetMapping("/importItemData")
    public ResultDTO importItemData(){
        return searchService.importItemData();
    }


    /**
     * 自动补全
     * @param key
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> suggestion(@RequestParam("key") String key){
        return searchService.suggestion(key);
    }


    /**
     * 过滤聚合
     * @param searchReqDTO
     * @return
     */
    @PostMapping("/filters")
    public Map<String,List<String>> filters(@RequestBody SearchReqDTO searchReqDTO){
        return searchService.filters(searchReqDTO);
    }

    /**
     * 分页查询
     * @param searchReqDTO
     * @return
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody SearchReqDTO searchReqDTO){
        return searchService.list(searchReqDTO);
    }


}
